using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace DesktopWidgetApp.Server.Models
{
    /// <summary>
    /// 团队实体模型
    /// 表示系统中的一个团队，可以包含多个成员
    /// </summary>
    public class Team
    {
        /// <summary>
        /// 团队ID
        /// </summary>
        [Key]
        public Guid Id { get; set; }

        /// <summary>
        /// 团队名称
        /// </summary>
        [Required]
        [MaxLength(100)]
        public string Name { get; set; }

        /// <summary>
        /// 团队描述
        /// </summary>
        [MaxLength(500)]
        public string Description { get; set; }

        /// <summary>
        /// 团队创建时间
        /// </summary>
        [Required]
        public DateTime CreatedAt { get; set; }

        /// <summary>
        /// 团队创建者ID
        /// </summary>
        [Required]
        public Guid CreatorId { get; set; }

        /// <summary>
        /// 团队创建者
        /// </summary>
        [ForeignKey("CreatorId")]
        public User Creator { get; set; }

        /// <summary>
        /// 团队成员关系
        /// </summary>
        public ICollection<TeamMember> Members { get; set; } = new List<TeamMember>();
    }

    /// <summary>
    /// 团队成员实体模型
    /// 表示用户与团队之间的关联关系
    /// </summary>
    public class TeamMember
    {
        /// <summary>
        /// 团队ID
        /// </summary>
        [Key, Column(Order = 0)]
        public Guid TeamId { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        [Key, Column(Order = 1)]
        public Guid UserId { get; set; }

        /// <summary>
        /// 成员在团队中的角色
        /// </summary>
        [Required]
        [MaxLength(50)]
        public string Role { get; set; } = "Member";

        /// <summary>
        /// 加入团队的时间
        /// </summary>
        [Required]
        public DateTime JoinedAt { get; set; }

        /// <summary>
        /// 所属团队
        /// </summary>
        [ForeignKey("TeamId")]
        public Team Team { get; set; }

        /// <summary>
        /// 团队成员用户
        /// </summary>
        [ForeignKey("UserId")]
        public User User { get; set; }
    }
}